package com.example.dongha.adapter;

import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
 * Created by liangkun on 2018/4/13.
 * 作用:recyleview的间距
 */

public class SpaceItemDecoration extends RecyclerView.ItemDecoration{
    private int space;

    public SpaceItemDecoration(int space) {
        //即你要设置的分割线的宽度 --这里设为10dp
        this.space = space;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        super.getItemOffsets(outRect, view, parent, state);
        //outRect就是你那个item条目的矩形
         //相当于 设置 left padding
        int position = parent.getChildAdapterPosition(view);
        //如果position 不是第一排0,1,2。我才设置间距
        if(position!=0&&position!=1&&position!=2){
            outRect.top = space;  //相当于 设置 top padding
        }


    }
}
